﻿using System;
using System.Windows;
using System.Windows.Controls;
using nRoute.Components;
using nRoute.Navigation;
using nRoute.Navigation.Containers;
using nRoute.Samples.FutureDesktop.Model;
using System.Windows.Input;

namespace nRoute.Samples.FutureDesktop
{
    public partial class Workspaces : Window
    {
        private INavigationContainer _container;

        public Workspaces()
        {
            InitializeComponent();
            
            this.SetRelayConverter<object, string>("DateTimeConverterRelay", (o) => DateTime.Today.ToString("dd"));
            this.SetRelayConverter<Workspace, string>("ActiveWorkspaceUrlConverterRelay", (w) =>
            {
                if (_container != null) _container.Navigated -= new EventHandler<NavigatedEventArgs>(ActiveContainer_Navigated);

                _container = NavigationService.DefaultNavigationHandler as INavigationContainer;
                if (_container == null) return string.Empty;
                _container.Navigated += new EventHandler<NavigatedEventArgs>(ActiveContainer_Navigated);

                this.NavigateUrlText.Text = _container.Url;
                return _container.Url;
            });
            //MouseLeftButtonDown += new MouseButtonEventHandler(MainWindow_MouseLeftButtonDown);
        }

#region Hanlders

        private void ActiveContainer_Navigated(object sender, NavigatedEventArgs e)
        {
            this.NavigateUrlText.Text = e.Request.RequestUrl;
        }

        private void SidePanels_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            DragMove();
        }

        private void CloseButton_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        private void RestoreButton_Click(object sender, RoutedEventArgs e)
        {
            this.WindowState = (this.WindowState == WindowState.Normal) ? WindowState.Maximized : WindowState.Normal;
        }

        private void MinimizeButton_Click(object sender, RoutedEventArgs e)
        {
            this.WindowState = WindowState.Minimized;
        }

#endregion

    }
}
